package com.zuipin.controller;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zuipin.entity.SysUser;
import com.zuipin.entity.product.ProductDetail;
import com.zuipin.entity.product.ProductExtInfo;
import com.zuipin.entity.product.ProductInfo;
import com.zuipin.entity.product.ProductPrice;
import com.zuipin.entity.product.PropertiesVal;
import com.zuipin.enums.ProductStatus;
import com.zuipin.enums.ProductType;
import com.zuipin.enums.RocketMQTagEnum;
import com.zuipin.framework.annotation.Inject;
import com.zuipin.framework.annotation.Json;
import com.zuipin.framework.annotation.Jsons;
import com.zuipin.framework.annotation.Valid;
import com.zuipin.framework.annotation.Valids;
import com.zuipin.framework.emuns.ErrorCode;
import com.zuipin.framework.exception.CustomException;
import com.zuipin.framework.result.PageResult;
import com.zuipin.framework.result.Result;
import com.zuipin.service.IProductDetailService;
import com.zuipin.service.IProductExtInfoService;
import com.zuipin.service.IProductInfoService;
import com.zuipin.service.IProductPriceService;
import com.zuipin.service.IProductPropertyValueService;
import com.zuipin.service.IPropertiesInfoService;
import com.zuipin.service.ISysUserService;
import com.zuipin.util.DateUtils;
import com.zuipin.util.Pagination;
import com.zuipin.util.RegexUtils;
import com.zuipin.vo.BackExtProDetailVo;
import com.zuipin.vo.BackProductInfoDetailVo;
import com.zuipin.vo.BackProductInfoVo;
import com.zuipin.vo.BackProductPlatformSearchVo;
import com.zuipin.vo.ProExtDetailVo;
import com.zuipin.vo.ProExtInfoVo;
import com.zuipin.vo.ProExtSerachVo;
import com.zuipin.vo.ProExtVo;
import com.zuipin.vo.ProPriceVo;
import com.zuipin.vo.ProSearchVo;
import com.zuipin.vo.ProVo;
import com.zuipin.vo.ProductAmountVo;
import com.zuipin.vo.ProductCashierVo;
import com.zuipin.vo.ProductDetailVo;
import com.zuipin.vo.ProductImgVo;
import com.zuipin.vo.ProductInfoVo;
import com.zuipin.vo.ProductModStatusVo;
import com.zuipin.vo.ProductPropertyValueVo;
import com.zuipin.vo.ProductSearchVo;
import com.zuipin.vo.PropValVo;
import com.zuipin.vo.SearchProductInfoVo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.sf.json.JSONObject;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 
 *
 * @ClassName ProductInfoController
 * @author wangcongyi
 * @date 2017年4月20日 下午3:22:46
 */
@Controller
@RequestMapping(value = "/product")
@Api(value = "商品", description = "商品信息-wangcongyi")
public class ProductInfoController {
	@Resource
	private IProductInfoService				productInfoService;
	@Resource
	private IProductDetailService			productDetailService;
	@Resource
	private IPropertiesInfoService			propertiesInfoService;
	@Resource
	private IProductPropertyValueService	productPropertyValueService;
	@Resource
	private IProductExtInfoService			productExtInfoService;
	@Resource
	private IProductPriceService			productPriceService;
	@Resource
	private ISysUserService					sysUserService;
	
	@Value("${imgpath.zpDomain}")
	private String							zpDomain;					// 图片拼接域名
	
	@Value("${imgpath.zpThumbnail230x184}")
	private String							zpThumbnail230x184;			// 缩略图拼接路径规格230X184
	
	@Value("${imgpath.zpThumbnail78x65}")
	private String							zpThumbnail78x65;			// 缩略图拼接路径规格78x65
	
	@Value("${imgpath.zpRawImage}")
	private String							zpRawImage;					// 原图拼接路径
	
	@Jsons({ @Json(type = ProductInfoVo.class), @Json(type = ProductInfo.class, exclude = "wuliuFenVal,makeFenVal,delFlag,createId,createTime,updateId,updateTime"),
			@Json(type = ProductExtInfo.class, exclude = "proSku,delFlag,createId,createTime,updateId,updateTime"),
			@Json(type = ProductPrice.class, include = "id,priceType,price"), @Json(type = ProductImgVo.class) })
	@RequestMapping(value = "/getProExtInfo", method = RequestMethod.GET)
	@ApiOperation(value = "518-查找单个商品信息(前台)-wangcongyi", notes = "查找单个商品信息")
	@Valids({ @Valid(name = "sysId", required = true), @Valid(name = "productSku", required = true, maxLength = 200), @Valid(name = "memberId"),
			@Valid(name = "device", required = true, regex = "WAP|PC") })
	@ApiImplicitParams({ @ApiImplicitParam(name = "sysId", value = "系统ID", required = true, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "device", value = "终端,WAP|PC", required = true, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "productSku", value = "商品编码", required = true, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "memberId", value = "会员ID", required = false, dataType = "long", paramType = "query") })
	public Result<ProductInfoVo> getProExtInfo(@RequestParam(required = true) Long sysId, @RequestParam(required = true) String device,
			@RequestParam(required = true) String productSku, @RequestParam(required = false) Long memberId) {
		Result<ProductInfoVo> result = new Result<>();
		
		boolean isLogin = false;
		JSONObject params = new JSONObject();
		params.put("sysId", sysId);
		params.put("device", device);
		params.put("productSku", productSku);
		// 判断是否有传会员ID
		if (memberId != null) {
			params.put("memberId", memberId);
			isLogin = true;
		}
		ProductInfoVo v = productInfoService.getProExtInfo(params, isLogin);
		
		if (v == null) {
			result.setErrorCode(ErrorCode.NOT_FIND);
			return result;
		}
		
		// 判断是否为积分商品
		if (productInfoService.isIntegralPro(productSku) != null) {
			// 获取商品积分价
			JSONObject param = new JSONObject();
			param.put("sysId", sysId);
			param.put("proSku", productSku);
			List<ProductPrice> prices = productPriceService.findByProSku(param);
			for (ProductPrice p : prices) {
				if (p.getPriceType().equals(ProductPrice.INTEGRAL)) {
					if (p.getPrice() == null) {
						v.setIntegralPrice(0);
					} else {
						v.setIntegralPrice(p.getPrice().intValue());
					}
				}
			}
		}
		
		result.setData(v);
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
	@Jsons({ @Json(type = ProductDetailVo.class), @Json(type = PropValVo.class), @Json(type = PropertiesVal.class, include = "id,catPropId,propVal"), })
	@RequestMapping(value = "/getProExtDetail", method = RequestMethod.GET)
	@ApiOperation(value = "518-查找单个商品详情(前台)-wangcongyi", notes = "查找单个商品详情")
	@Valids({ @Valid(name = "sysId", required = true), @Valid(name = "productSku", required = true, maxLength = 200), @Valid(name = "device", required = true, regex = "WAP|PC") })
	@ApiImplicitParams({ @ApiImplicitParam(name = "sysId", value = "系统ID", required = true, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "productSku", value = "商品编码", required = true, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "device", value = "终端,WAP|PC", required = true, dataType = "string", paramType = "query") })
	public Result<?> getProExtDetail(@RequestParam(required = true) Long sysId, @RequestParam(required = true) String productSku, @RequestParam(required = true) String device) {
		Result<ProductDetailVo> result = new Result<>();
		JSONObject params = new JSONObject();
		params.put("sysId", sysId);
		params.put("productSku", productSku);
		params.put("device", device);
		ProductDetailVo vo = new ProductDetailVo();
		ProductDetail productDetail = productDetailService.selectByProSku(params);
		if (null != productDetail) {
			vo.setContent(productDetail.getContent());
		}
		
		// update by zjj
		// List<PropValVo> propValList = propertiesInfoService.getPropValList(sysId, productSku, device);
		
		vo.setPropValList(propertiesInfoService.selectPropValInfo(params));
		// vo.setPropValList(propValList);
		result.setData(vo);
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
	@ResponseBody
	@RequestMapping(value = "/queryProExtInfo", method = RequestMethod.POST)
	@ApiOperation(value = "518-查找多个商品信息(前台)-wangcongyi", notes = "查找多个商品信息")
	@Valids({ @Valid(name = "proExt.memberId"), @Valid(name = "proExt.sysId", required = true), @Valid(name = "proExt.device", required = true, regex = "WAP|PC"),
			@Valid(name = "proExt.productExtList.proSku", maxLength = 200), @Valid(name = "proExt.productExtList.proNo"), @Valid(name = "proExt.productExtList.productExtId"),
			@Valid(name = "proExt.productExtList.proNum"), @Valid(name = "proExt.productExtList.proId"), })
	public Result<?> queryProExtInfo(@RequestBody @ApiParam ProExtSerachVo proExt) {
		Result<List<ProExtInfoVo>> result = new Result<List<ProExtInfoVo>>();
		boolean isLogin = false;
		// 判断是否有传会员ID
		if (null != proExt.getMemberId()) {
			isLogin = true;
		}
		result.setData(productInfoService.queryProExtInfo(proExt, isLogin));
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
	@ResponseBody
	@RequestMapping(value = "/seachProduct", method = RequestMethod.POST)
	@ApiOperation(value = "518-分页查询商品信息(前台)-wangcongyi", notes = "分页查询商品信息")
	@Valids({ @Valid(name = "pro.sysId", required = true), @Valid(name = "pro.device", required = true, regex = "WAP|PC"), @Valid(name = "pro.seachKey", maxLength = 200),
			@Valid(name = "pro.catId"), @Valid(name = "pro.sort", regex = "1|2|3|4"), @Valid(name = "pro.orderBy", regex = "DESC|desc|ASC|asc"),
			@Valid(name = "pro.propertiesValList.propId"), @Valid(name = "pro.propertiesValList.propValId"), @Valid(name = "page.pageNumber", required = true),
			@Valid(name = "page.pageSize", required = true), })
	@ApiImplicitParams({ @ApiImplicitParam(name = "page.pageNumber", value = "页码", required = true, dataType = "integer", paramType = "query"),
			@ApiImplicitParam(name = "page.pageSize", value = "单页记录数", required = true, dataType = "integer", paramType = "query"), })
	public Result<?> seachProduct(@RequestBody @ApiParam ProSearchVo pro, @Inject @ApiIgnore Pagination page) {
		PageResult<List<ProExtVo>> result = new PageResult<List<ProExtVo>>();
		JSONObject params = new JSONObject();
		params.put("pageIndex", page.getOffset());
		params.put("pageSize", page.getPageSize());
		result.setData(productInfoService.seachProduct(pro, params));
		result.setTotal_record(productInfoService.getTotalRecord(pro));
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
	@ResponseBody
	@RequestMapping(value = "/selectByProSku", method = RequestMethod.GET)
	@ApiOperation(value = "518-根据商品SKU查询商品信息和价格-wangcongyi", notes = "根据商品SKU查询商品信息和价格")
	@Valids({ @Valid(name = "proSku", maxLength = 200) })
	@ApiImplicitParams({ @ApiImplicitParam(name = "proSku", value = "商品SKU", required = true, dataType = "string", paramType = "query") })
	public Result<?> selectByProSku(@RequestParam(required = true) String proSku) {
		Result<Map<String, Object>> result = new Result<>();
		result.setData(productInfoService.getByProSku(proSku));
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
	@Jsons({ @Json(type = ProExtDetailVo.class, exclude = "productExtInfo,productPrices,productImgs,productDetails"),
			@Json(type = ProductInfo.class, include = "id,proSku,proName,catName,unint,proShortName,supplierCatName,supplierName,businessType,isVirtual,weight,specifications"),
			@Json(type = PropValVo.class), @Json(type = PropertiesVal.class, include = "id,catPropId,propVal"), })
	@RequestMapping(value = "/selectProForGeneral", method = RequestMethod.GET)
	@ApiOperation(value = "查找单个商品信息详情(后台通用)", notes = "查找单个商品信息详情")
	public Result<?> selectExtForGeneral(@ApiParam(name = "productSku", value = "商品编码", required = true) @RequestParam(required = true) String productSku) throws CustomException {
		Result<ProExtDetailVo> result = new Result<ProExtDetailVo>();
		JSONObject params = new JSONObject();
		params.put("productSku", productSku);
		result.setData(productInfoService.selectProForGeneral(params));
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
	@Jsons({ @Json(type = ProExtDetailVo.class, exclude = "productDetails,productImgs"),
			@Json(type = ProductInfo.class, include = "id,proSku,proName,catName,unint,proShortName,supplierCatName,supplierName,businessType,isVirtual,weight,specifications"),
			@Json(type = ProductExtInfo.class, include = "id,title,subTitle,buyLowLimit,buyUpperLimit,virtualStock,tagId,tagName"),
			@Json(type = ProductPrice.class, include = "id,sysId,priceType,price"), @Json(type = PropValVo.class),
			@Json(type = PropertiesVal.class, include = "id,catPropId,propVal"), })
	@RequestMapping(value = "/selectPro", method = RequestMethod.GET)
	@ApiOperation(value = "查找单个商品信息详情(后台分系统)", notes = "查找单个商品信息详情")
	public Result<?> selectExt(@ApiParam(name = "sysId", value = "系统ID", required = true) @RequestParam(required = true) Long sysId,
			@ApiParam(name = "productSku", value = "商品编码", required = true) @RequestParam(required = true) String productSku) throws CustomException {
		Result<ProExtDetailVo> result = new Result<ProExtDetailVo>();
		JSONObject params = new JSONObject();
		params.put("sysId", sysId);
		params.put("productSku", productSku);
		result.setData(productInfoService.selectProDetail(params));
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
	@Jsons({ @Json(type = ProductInfo.class, include = "id,proSku,proName,specifications,unint,proType,businessType,createTime,supplierName") })
	@RequestMapping(value = "/findProduct", method = RequestMethod.POST)
	@ApiOperation(value = "分页查询商品信息(后台通用)", notes = "分页查询商品信息")
	@Valids({ @Valid(name = "search.proSku", maxLength = 200), @Valid(name = "search.proName", maxLength = 500),
			@Valid(name = "search.businessType", regex = "JOIN_SALES|SELF_SALES"), @Valid(name = "search.proType", regex = "PRO|TEABAG|SAMPLE"), @Valid(name = "search.status"),
			@Valid(name = "search.supplierName", maxLength = 50), @Valid(name = "page.pageNumber", required = true), @Valid(name = "page.pageSize", required = true), })
	@ApiImplicitParams({ @ApiImplicitParam(name = "search.proSku", value = "商品SKU", dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "search.proName", value = "商品名称", dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "search.businessType", value = "商品模式,JOIN_SALES|SELF_SALES", dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "search.proType", value = "商品类型,PRO|TEABAG|SAMPLE", dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "search.status", value = "状态（启用 禁用）", dataType = "integer", paramType = "query"),
			@ApiImplicitParam(name = "search.supplierName", value = "供应商名称", dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "page.pageNumber", value = "页码", required = true, dataType = "integer", paramType = "query"),
			@ApiImplicitParam(name = "page.pageSize", value = "单页记录数", required = true, dataType = "integer", paramType = "query") })
	public Result<?> findProduct(@Inject @ApiIgnore ProductSearchVo search, @Inject @ApiIgnore Pagination page) {
		PageResult<List<ProductInfo>> result = new PageResult<List<ProductInfo>>();
		List<ProductInfo> productInfos = productInfoService.findProduct(search, page);
		result.setData(productInfos);
		result.setTotal_record(page.getTotalRecord());
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
	@Jsons({ @Json(type = ProductInfo.class, include = "proSku,proName,specifications,unint,proType,businessType,createTime,supplierName") })
	@RequestMapping(value = "/findProductByCatId", method = RequestMethod.POST)
	@ApiOperation(value = "商品分类树查找商品信息列表(后台通用)", notes = "商品分类树查找商品信息列表")
	@Valids({ @Valid(name = "search.catId"), @Valid(name = "page.pageNumber", required = true), @Valid(name = "page.pageSize", required = true), })
	@ApiImplicitParams({ @ApiImplicitParam(name = "search.catId", value = "分类ID", dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "page.pageNumber", value = "页码", required = true, dataType = "integer", paramType = "query"),
			@ApiImplicitParam(name = "page.pageSize", value = "单页记录数", required = true, dataType = "integer", paramType = "query") })
	public Result<?> findProductByCatId(@Inject @ApiIgnore ProductSearchVo search, @Inject @ApiIgnore Pagination page) {
		PageResult<List<ProductInfo>> result = new PageResult<List<ProductInfo>>();
		List<ProductInfo> productInfos = productInfoService.findProductByCatId(search, page);
		result.setData(productInfos);
		result.setTotal_record(page.getTotalRecord());
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
	@Jsons({ @Json(type = ProductInfo.class, include = "id,proSku,proName,specifications,unint,proType,businessType,state,onShelfTime") })
	@RequestMapping(value = "/findProductExt", method = RequestMethod.POST)
	@ApiOperation(value = "分页查询商品信息(分系统)", notes = "分页查询商品信息")
	@Valids({ @Valid(name = "search.proSku", maxLength = 200), @Valid(name = "search.proName", maxLength = 500),
			@Valid(name = "search.businessType", regex = "JOIN_SALES|SELF_SALES"), @Valid(name = "search.proType", regex = "PRO|TEABAG|SAMPLE"),
			@Valid(name = "search.state", regex = "ON_SHELF|OFF_SHELF"), @Valid(name = "search.status"), @Valid(name = "search.title", maxLength = 200),
			@Valid(name = "search.subTitle", maxLength = 100), @Valid(name = "search.sysId", required = true), @Valid(name = "page.pageNumber", required = true),
			@Valid(name = "page.pageSize", required = true), })
	@ApiImplicitParams({ @ApiImplicitParam(name = "search.proSku", value = "商品SKU", dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "search.proName", value = "商品名称", dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "search.businessType", value = "商品模式,JOIN_SALES|SELF_SALES", dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "search.proType", value = "商品类型,PRO|TEABAG|SAMPLE", dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "search.state", value = "状态（上架 下架）,ON_SHELF|OFF_SHELF", dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "search.status", value = "状态（启用 禁用）", dataType = "integer", paramType = "query"),
			@ApiImplicitParam(name = "search.title", value = "商品标题", dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "search.subTitle", value = "商品副标题", dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "search.sysId", value = "系统ID", required = true, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "page.pageNumber", value = "页码", required = true, dataType = "integer", paramType = "query"),
			@ApiImplicitParam(name = "page.pageSize", value = "单页记录数", required = true, dataType = "integer", paramType = "query") })
	public Result<?> findProductExt(@Inject @ApiIgnore ProductSearchVo search, @Inject @ApiIgnore Pagination page) {
		PageResult<List<ProductInfo>> result = new PageResult<List<ProductInfo>>();
		List<ProductInfo> productInfos = productInfoService.findProductExt(search, page);
		result.setData(productInfos);
		result.setTotal_record(page.getTotalRecord());
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
	@Jsons({ @Json(type = ProductInfo.class, include = "id,proSku,proName,specifications,unint,proType,businessType,state,onShelfTime") })
	@RequestMapping(value = "/findProductExtByCatId", method = RequestMethod.POST)
	@ApiOperation(value = "商品分类树查找商品信息列表(分系统)", notes = "商品分类树查找商品信息列表")
	@Valids({ @Valid(name = "search.catId"), @Valid(name = "search.sysId", required = true), @Valid(name = "page.pageNumber", required = true),
			@Valid(name = "page.pageSize", required = true), })
	@ApiImplicitParams({ @ApiImplicitParam(name = "search.catId", value = "分类ID", dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "search.sysId", value = "系统ID", required = true, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "page.pageNumber", value = "页码", required = true, dataType = "integer", paramType = "query"),
			@ApiImplicitParam(name = "page.pageSize", value = "单页记录数", required = true, dataType = "integer", paramType = "query") })
	public Result<?> findProductExtByCatId(@Inject @ApiIgnore ProductSearchVo search, @Inject @ApiIgnore Pagination page) {
		PageResult<List<ProductInfo>> result = new PageResult<List<ProductInfo>>();
		List<ProductInfo> productInfos = productInfoService.findProductExtByCatId(search, page);
		result.setData(productInfos);
		result.setTotal_record(page.getTotalRecord());
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
	@Jsons({ @Json(type = ProductInfo.class, include = "id,proSku,unint,catName,businessType,proName,proShortName,supplierName,weight,specifications") })
	@RequestMapping(value = "/selectById", method = RequestMethod.GET)
	@ApiOperation(value = "根据商品ID查询商品信息(后台)", notes = "根据商品ID查询商品信息")
	@Valids({ @Valid(name = "id", required = true) })
	@ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "商品ID", required = true, dataType = "long", paramType = "query") })
	public Result<?> selectById(@RequestParam(required = true) Long id) {
		Result<ProductInfo> result = new Result<ProductInfo>();
		result.setData(productInfoService.selectById(id));
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
	@ResponseBody
	@RequestMapping(value = "/getProBySku", method = RequestMethod.GET)
	@ApiOperation(value = "根据商品SKU查询商品信息", notes = "根据商品SKU查询商品信息")
	@Valids({ @Valid(name = "proSku", required = true) })
	@ApiImplicitParams({ @ApiImplicitParam(name = "proSku", value = "商品Sku", required = true, dataType = "string", paramType = "query") })
	public Result<?> getProBySku(@RequestParam(required = true) String proSku) {
		Result<ProductInfo> result = new Result<ProductInfo>();
		result.setData(productInfoService.getProBySku(proSku));
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
	@ResponseBody
	@RequestMapping(value = "/createXpPro", method = RequestMethod.POST)
	@ApiOperation(value = "创建体验品(后台)", notes = "创建体验品(后台)")
	@Valids({ @Valid(name = "productInfo.id", required = true), @Valid(name = "productInfo.sysId", required = true), @Valid(name = "productInfo.proNo"),
			@Valid(name = "productInfo.proSku", required = true), @Valid(name = "productInfo.proName", required = true, maxLength = 500),
			@Valid(name = "productInfo.proShortName", required = true, maxLength = 200), @Valid(name = "productInfo.weight", required = true),
			@Valid(name = "productInfo.netWeight", maxValue = 9), @Valid(name = "productInfo.businessType", required = true, regex = "JOIN_SALES|SELF_SALES"),
			@Valid(name = "productInfo.proType", required = true, regex = "PRO|TEABAG|SAMPLE"), @Valid(name = "productInfo.suppilerId"), @Valid(name = "productInfo.validDay"),
			@Valid(name = "productInfo.unint"), @Valid(name = "productInfo.specifications"), @Valid(name = "productInfo.isCanSplit"), @Valid(name = "productInfo.isVirtual"),
			@Valid(name = "productInfo.isDis"), @Valid(name = "productInfo.brandId"), @Valid(name = "price.productPrices.sysId", required = true),
			@Valid(name = "price.productPrices.priceType", required = true), @Valid(name = "price.productPrices.price", required = true) })
	@ApiImplicitParams({ @ApiImplicitParam(name = "productInfo.id", value = "商品ID", required = true, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "productInfo.sysId", value = "系统ID", required = true, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "productInfo.proNo", value = "外部商品编号", required = false, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "productInfo.proSku", value = "商品SKU", required = true, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "productInfo.proName", value = "商品名称", required = true, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "productInfo.proShortName", value = "商品简称", required = true, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "productInfo.weight", value = "重量", required = false, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "productInfo.netWeight", value = "净重", required = false, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "productInfo.businessType", value = "业务类别,JOIN_SALES|SELF_SALES", required = true, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "productInfo.proType", value = "商品类型,PRO|TEABAG|SAMPLE", required = true, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "productInfo.suppilerId", value = "供应商ID", required = false, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "productInfo.validDay", value = "商品保质期", required = false, dataType = "integer", paramType = "query"),
			@ApiImplicitParam(name = "productInfo.unint", value = "单位", required = false, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "productInfo.specifications", value = "规格", required = false, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "productInfo.isCanSplit", value = "是否可拆卸", required = false, dataType = "integer", paramType = "query"),
			@ApiImplicitParam(name = "productInfo.isVirtual", value = "是否虚拟产品", required = false, dataType = "integer", paramType = "query"),
			@ApiImplicitParam(name = "productInfo.isDis", value = "是否自动拆分", required = false, dataType = "integer", paramType = "query"),
			@ApiImplicitParam(name = "productInfo.brandId", value = "品牌", required = false, dataType = "long", paramType = "query") })
	public Result<?> createXpPro(@Inject @ApiIgnore ProductInfo productInfo, @RequestBody @ApiParam ProPriceVo price) {
		Result<Boolean> result = new Result<>();
		JSONObject params = new JSONObject();
		params.put("proSku", productInfo.getProSku());
		params.put("proNo", productInfo.getProNo());
		boolean status = false;
		List<ProductInfo> checkInfos = null;
		checkInfos = productInfoService.checkPro(params);
		if (checkInfos.size() > 0) {
			// 提示商品Sku或编码不唯一
			result.setErrorCode(ErrorCode.OBJECT_EXIST);
			result.setMessage("商品Sku或编码不唯一!");
			result.setData(null);
		} else {
			status = productInfoService.insertXpPro(productInfo, price);
			if (status) {
				result.setErrorCode(ErrorCode.SUCCESS);
				result.setMessage("体验品添加成功！");
				result.setData(status);
			} else {
				result.setErrorCode(ErrorCode.ELSE);
				result.setMessage("体验品添加失败！");
				result.setData(status);
			}
			
		}
		return result;
	}
	
	@ResponseBody
	@RequestMapping(value = "/updatePro", method = RequestMethod.POST)
	@ApiOperation(value = "商品信息修改(后台)", notes = "商品信息修改(后台)")
	@Valids({ @Valid(name = "productInfo.id", required = true), @Valid(name = "productInfo.sysId", required = true), @Valid(name = "productInfo.proNo"),
			@Valid(name = "productInfo.proSku", required = true), @Valid(name = "productInfo.proName", required = true, maxLength = 500),
			@Valid(name = "productInfo.proShortName", required = true, maxLength = 200), @Valid(name = "productInfo.supplierCatName", maxLength = 200),
			@Valid(name = "productInfo.weight", required = true), @Valid(name = "productInfo.netWeight", maxValue = 9),
			@Valid(name = "productInfo.businessType", required = true, regex = "JOIN_SALES|SELF_SALES"),
			@Valid(name = "productInfo.proType", required = true, regex = "PRO|TEABAG|SAMPLE"), @Valid(name = "productInfo.suppilerId"), @Valid(name = "productInfo.validDay"),
			@Valid(name = "productInfo.unint"), @Valid(name = "productInfo.specifications"), @Valid(name = "productInfo.isCanSplit"), @Valid(name = "productInfo.isVirtual"),
			@Valid(name = "productInfo.isDis"), @Valid(name = "productInfo.brandId"), @Valid(name = "prop.productPropertyValues.propId"),
			@Valid(name = "prop.productPropertyValues.propValId"), @Valid(name = "prop.productPropertyValues.propVal"), @Valid(name = "prop.productPropertyValues.id"), })
	@ApiImplicitParams({ @ApiImplicitParam(name = "productInfo.id", value = "原商品ID", required = true, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "productInfo.sysId", value = "系统ID", required = true, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "productInfo.proNo", value = "外部商品编号", required = false, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "productInfo.proSku", value = "商品SKU", required = true, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "productInfo.proName", value = "商品名称", required = true, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "productInfo.proShortName", value = "商品简称", required = true, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "productInfo.supplierCatName", value = "供应商定义品名", required = true, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "productInfo.weight", value = "重量", required = false, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "productInfo.netWeight", value = "净重", required = false, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "productInfo.businessType", value = "业务类别,JOIN_SALES|SELF_SALES", required = true, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "productInfo.proType", value = "商品类型,PRO|TEABAG|SAMPLE", required = true, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "productInfo.suppilerId", value = "供应商ID", required = false, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "productInfo.validDay", value = "商品保质期", required = false, dataType = "integer", paramType = "query"),
			@ApiImplicitParam(name = "productInfo.unint", value = "单位", required = false, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "productInfo.specifications", value = "规格", required = false, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "productInfo.isCanSplit", value = "是否可拆卸", required = false, dataType = "integer", paramType = "query"),
			@ApiImplicitParam(name = "productInfo.isVirtual", value = "是否虚拟产品", required = false, dataType = "integer", paramType = "query"),
			@ApiImplicitParam(name = "productInfo.isDis", value = "是否自动拆分", required = false, dataType = "integer", paramType = "query"),
			@ApiImplicitParam(name = "productInfo.brandId", value = "品牌", required = false, dataType = "long", paramType = "query") })
	public Result<?> updatePro(@Inject @ApiIgnore ProductInfo productInfo, @RequestBody @ApiParam ProductPropertyValueVo prop) {
		Result<Boolean> result = new Result<>();
		JSONObject params = new JSONObject();
		params.put("proSku", productInfo.getProSku());
		params.put("proNo", productInfo.getProNo());
		params.put("id", productInfo.getId());
		boolean status = false;
		List<ProductInfo> checkInfos = null;
		checkInfos = productInfoService.checkPro(params);
		if (checkInfos.size() > 0) {
			// 提示商品Sku或编码不唯一
			result.setErrorCode(ErrorCode.OBJECT_EXIST);
			result.setMessage("商品Sku或编码不唯一!");
			result.setData(null);
		} else {
			status = productInfoService.updatePro(productInfo, prop);
			if (status) {
				result.setErrorCode(ErrorCode.SUCCESS);
				result.setMessage("商品信息修改成功！");
				result.setData(status);
			} else {
				result.setErrorCode(ErrorCode.ELSE);
				result.setMessage("商品信息修改失败！");
				result.setData(status);
			}
		}
		return result;
	}
	
	@ResponseBody
	@RequestMapping(value = "/updateSalesByProSku", method = RequestMethod.POST)
	@ApiOperation(value = "更新商品销量数", notes = "更新商品销量数")
	public Result<?> updateSalesByProSku(@ApiParam(name = "productSku", value = "商品SKU", required = true) @RequestParam(required = true) String productSku,
			@ApiParam(name = "salesNum", value = "商品销量数", required = true) @RequestParam(required = true) BigDecimal salesNum) {
		Result<Boolean> result = new Result<>();
		result.setData(productInfoService.updateSalesByProSku(productSku, salesNum));
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
	@ResponseBody
	@RequestMapping(value = "/selectByProNo", method = RequestMethod.GET)
	@ApiOperation(value = "根据商品编号查询商品信息", notes = "根据商品编号查询商品信息")
	public Result<?> selectByProNo(@ApiParam(name = "proNo", value = "商品内部编号", required = true) @RequestParam(required = true) String proNo) {
		Result<ProductInfo> result = new Result<ProductInfo>();
		result.setData(productInfoService.selectByProNo(proNo));
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
	@ResponseBody
	@RequestMapping(value = "/getStock", method = RequestMethod.GET)
	@ApiOperation(value = "518-根据商品SKU查询商品有效库存-wangcongyi", notes = "根据商品SKU查询商品有效库存")
	@Valids({ @Valid(name = "proSku", required = true, maxLength = 200) })
	@ApiImplicitParams({ @ApiImplicitParam(name = "proSku", value = "商品SKU", required = true, dataType = "string", paramType = "query") })
	public Result<?> getStock(@RequestParam String proSku) throws CustomException {
		Result<Map<String, Object>> result = new Result<>();
		// 获取商品库存Map集
		Map<String, Map<String, Object>> products = productInfoService.getStock(proSku);
		// 获取Sku对应的有效库存Map
		Map<String, Object> validstocks = products.get(proSku);
		BigDecimal stockNum = (BigDecimal) validstocks.get("validStock");
		int validStock = 0;
		if (null != stockNum) {
			validStock = stockNum.intValue();
		}
		Map<String, Object> proStockMap = new HashMap<String, Object>();
		proStockMap.put("validStock", validStock);
		result.setData(proStockMap);
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
	@ResponseBody
	@RequestMapping(value = "/findPro", method = RequestMethod.POST)
	@ApiOperation(value = "三期-获取商品信息（SKU、名称、价格）并分页-wangcongyi", notes = "获取商品信息（SKU、名称、价格）并分页" + "</br>返回码" + "</br>0-成功" + "</br>1001-参数错误" + "</br>1002-必填项未填写"
			+ "</br>1004-系统异常")
	@Valids({ @Valid(name = "sysId", required = true), @Valid(name = "proSkus"), @Valid(name = "page.pageNumber", required = true),
			@Valid(name = "page.pageSize", required = true), })
	@ApiImplicitParams({ @ApiImplicitParam(name = "proSkus", value = "商品SKU集", required = false, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "sysId", value = "系统ID", required = true, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "page.pageNumber", value = "页码", required = true, dataType = "integer", paramType = "query"),
			@ApiImplicitParam(name = "page.pageSize", value = "单页记录数", required = true, dataType = "integer", paramType = "query"), })
	public Result<List<ProVo>> findPro(@RequestParam Long sysId, @RequestParam(required = false) String proSkus, @Inject @ApiIgnore Pagination page) {
		PageResult<List<ProVo>> result = new PageResult<>();
		JSONObject params = new JSONObject();
		params.put("sysId", sysId);
		if (null != proSkus) {
			String[] arr = proSkus.split(",");
			StringBuilder proSkuBuilder = new StringBuilder();
			String sp = "";
			for (int i = 0; i < arr.length; i++) {
				proSkuBuilder.append(sp);
				proSkuBuilder.append("'");
				proSkuBuilder.append(arr[i]);
				proSkuBuilder.append("'");
				sp = ",";
			}
			params.put("proSkus", proSkuBuilder.toString());
		}
		result.setData(productInfoService.findPro(params, page));
		result.setTotal_record(page.getTotalRecord());
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
	@ResponseBody
	@RequestMapping(value = "/searchBySkuFromBack", method = RequestMethod.GET)
	@ApiOperation(value = "后台新建订单商品查询接口-wuyicheng", notes = "根据商品ID查询商品信息-wuyicheng" + "</br>返回码" + "</br>0-成功" + "</br>1001-参数异常" + "</br>1004-系统异常" + "</br>2000-商品不存在"
			+ "</br>4001-该商品未上架" + "</br>4034-会员等级异常")
	@Valids({ @Valid(name = "device", required = true, regex = "PC|WAP") })
	@ApiImplicitParams({ @ApiImplicitParam(name = "memberId", value = "会员ID", required = true, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "sysId", value = "系统ID", required = true, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "proSku", value = "商品SkU", required = true, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "proNum", value = "购买数量", required = true, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "device", value = "PC|WAP", required = true, dataType = "string", paramType = "query") })
	public Result<ProductAmountVo> searchBySkuFromBack(@RequestParam(required = true) Long memberId, @RequestParam(required = true) Long sysId,
			@RequestParam(required = true) String proSku, @RequestParam(required = true) BigDecimal proNum, @RequestParam(required = true) String device) throws CustomException {
		Result<ProductAmountVo> result = productInfoService.searchBySkuFromBack(memberId, sysId, proSku, proNum, device);
		return result;
	}
	
	// -----------------------------------------------------------
	@ResponseBody
	@RequestMapping(value = "/modifyStatus", method = RequestMethod.POST)
	@ApiOperation(value = "商品启用禁用(后台)", notes = "商品启用禁用(后台)")
	@Valids({ @Valid(name = "proId", required = true), @Valid(name = "status", required = true) })
	@ApiImplicitParams({ @ApiImplicitParam(name = "proId", value = "商品ID", required = true, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "status", value = "状态（禁用 启用）", required = true, dataType = "integer", paramType = "query"),
			@ApiImplicitParam(name = "updateId", value = "修改人ID", required = true, dataType = "long", paramType = "query"), })
	public Result<?> modifyStatus(@RequestParam Long proId, @RequestParam Short status, @RequestParam Long updateId) {
		Result<Integer> result = new Result<>();
		JSONObject params = new JSONObject();
		params.put("proId", proId);
		params.put("status", status);
		// 判断是否已经启用或禁用状态
		ProductInfo productInfo = productInfoService.isExists(params);
		StringBuilder statusStr = new StringBuilder();
		// 同步商品状态
		ProductModStatusVo productModStatusVo = new ProductModStatusVo();
		ProductInfo oldProductInfo = productInfoService.findProById(proId);
		if (oldProductInfo != null) {
			productModStatusVo.setProNos(oldProductInfo.getProSku());
		}
		// 查询修改人信息
		SysUser sysUser = sysUserService.findById(updateId);
		if (sysUser != null) {
			productModStatusVo.setUpator(sysUser.getRealName());
		}
		// 判断用户传值
		if (status.equals(ProductInfo.ENABLE)) {
			statusStr.append("启用");
			productModStatusVo.setProductStatus(ProductStatus.上架);
		} else {
			statusStr.append("禁用");
			productModStatusVo.setProductStatus(ProductStatus.禁用);
		}
		if (null == productInfo) {
			// 更新状态
			boolean falg = productInfoService.modifyStatus(params);
			if (falg) {
				if (status.equals(ProductInfo.DISABLE)) {
					// 修改所有平台上架的商品下架、并发送同步信息
					List<ProductExtInfo> productExtInfos = productExtInfoService.findExtProByProId(proId);
					if (productExtInfos != null && productExtInfos.size() > 0) {
						/*// 并发送同步信息
						ProductModStatusVo productModStatusVos = new ProductModStatusVo();
						productModStatusVos.setProductStatus(ProductStatus.下架);
						if (sysUser != null) {
							productModStatusVo.setUpator(sysUser.getRealName());
						}
						productModStatusVos.setUpdateTime(DateUtils.getCurrentDateTime());*/
						/*// 拼接下架的商品集
						StringBuffer proNos = new StringBuffer();*/
						for (ProductExtInfo productExtInfo : productExtInfos) {
							// 下架
							JSONObject object = new JSONObject();
							object.put("proExtId", productExtInfo.getId());
							object.put("state", ProductExtInfo.OFF_SHELF);
							object.put("sysId", productExtInfo.getSysId());
							object.put("offShelfTime", DateUtils.getCurrentDateTime());
							productExtInfoService.modifyState(object);
							/*if (productExtInfo.getProSku() != null) {
								proNos.append(productExtInfo.getProSku()).append(",");
							}*/
						}
						/*// 发送同步信息
						productModStatusVos.setProNos(proNos.toString());
						productInfoService.sendProductInfoToErp(com.alibaba.fastjson.JSONObject.toJSON(productModStatusVos).toString(),
								RocketMQTagEnum.TO_MOD_PEODUCT_STATE_FROM_CBS.toString());*/
					}
				}
				result.setErrorCode(ErrorCode.SUCCESS);
				result.setMessage("商品[" + proId + "]" + statusStr + "成功！");
				// 发送同步信息
				productModStatusVo.setUpdateTime(DateUtils.getCurrentDateTime());
				productInfoService.sendProductInfoToErp(com.alibaba.fastjson.JSONObject.toJSON(productModStatusVo).toString(),
						RocketMQTagEnum.TO_MOD_PEODUCT_STATE_FROM_CBS.toString());
			} else {
				result.setErrorCode(ErrorCode.ELSE);
				result.setMessage("商品[" + proId + "]" + statusStr + "失败！");
			}
		} else {
			result.setErrorCode(ErrorCode.ELSE);
			result.setMessage("商品[" + proId + "]不可" + statusStr);
		}
		return result;
	}
	
	@ResponseBody
	@RequestMapping(value = "/searchProDetail", method = RequestMethod.GET)
	@ApiOperation(value = "后台商品编号查询商品详细信息-添加!!平台!!商品之前-huihang", notes = "后台商品编号查询商品详细信息-（添加平台商品之前使用）")
	@Valids({ @Valid(name = "sysId", required = true), @Valid(name = "proSku", required = true, maxLength = 20) })
	@ApiImplicitParams({ @ApiImplicitParam(name = "sysId", value = "系统ID", required = true, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "proSku", value = "商品SKU", required = true, dataType = "string", paramType = "query"), })
	public Result<BackExtProDetailVo> searchProDetail(@RequestParam Long sysId, @RequestParam String proSku) {
		if (proSku != null) {
			proSku = proSku.trim();
		}
		Result<BackExtProDetailVo> result = productInfoService.searchProDetail(sysId, proSku);
		return result;
	}
	
	@ResponseBody
	@RequestMapping(value = "/searchBackProductInfo", method = RequestMethod.GET)
	@ApiOperation(value = "后台查询通用商品SKU列表-huihang", notes = "后台查询通用商品SKU列表")
	@Valids({ @Valid(name = "search.catId", required = true), })
	@ApiImplicitParams({ @ApiImplicitParam(name = "search.catId", value = "品类ID", required = true, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "search.proSku", value = "商品Sku", required = false, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "search.proName", value = "商品名称", required = false, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "search.proType", value = "商品类型 [商品：PRO],[体验品：EXPERIENCE]", required = false, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "search.status", value = "商品状态[1正常 ],[2 禁用]", required = false, dataType = "short", paramType = "query"),
			@ApiImplicitParam(name = "search.isExchangeIntegral", value = "是否积分兑换 [0：否][1：是]", required = false, dataType = "short", paramType = "query"),
			@ApiImplicitParam(name = "search.businessType", value = "商品模式  [自营 :SELF_SALES] , [联营:JOIN_SALES]", required = false, dataType = "String", paramType = "query"),
			@ApiImplicitParam(name = "search.suppilerName", value = "供应商名字", required = false, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "search.beginCreateTime", value = "开始创建时间", required = false, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "search.endCreateTime", value = "结束创建时间", required = false, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "page.pageNumber", value = "页码", required = true, dataType = "integer", paramType = "query"),
			@ApiImplicitParam(name = "page.pageSize", value = "单页记录数", required = true, dataType = "integer", paramType = "query"), })
	public Result<List<BackProductInfoVo>> searchBackProductInfo(@Inject @ApiIgnore BackProductPlatformSearchVo search, @Inject @ApiIgnore Pagination page) {
		PageResult<List<BackProductInfoVo>> result = productInfoService.findBackProductInfo(search, page);
		return result;
	}
	
	@ResponseBody
	@RequestMapping(value = "/findProductInfoDetail", method = RequestMethod.POST)
	@ApiOperation(value = "后台查询通用商品详情SKU-huihang", notes = "后台查询通用商品详情SKU")
	@Valids({ @Valid(name = "proId", required = true), })
	@ApiImplicitParams({ @ApiImplicitParam(name = "proId", value = "商品ID", required = true, dataType = "long", paramType = "query"), })
	public Result<BackProductInfoDetailVo> findProductInfoDetail(@RequestParam Long proId) {
		Result<BackProductInfoDetailVo> result = productInfoService.findBackProductInfoDetail(proId);
		return result;
	}
	
	@ResponseBody
	@RequestMapping(value = "/insertOrUpdateProductInfo", method = RequestMethod.POST)
	@ApiOperation(value = "后台添加(修改)通用商品SKU-huihang", notes = "后台添加(修改)通用商品SKU," + "</br>修改BackProductInfoDetailVo.id必填")
	@Valids({ @Valid(name = "proInfoDetail.id", required = false), @Valid(name = "proInfoDetail.updateId", required = true),
			@Valid(name = "proInfoDetail.proSku", required = false, maxLength = 20, regex = RegexUtils.STR_ENG_NUM_LINE),
			@Valid(name = "proInfoDetail.proNo", required = false, maxLength = 20, regex = RegexUtils.STR_ENG_NUM_LINE), @Valid(name = "proInfoDetail.catId", required = true),
			@Valid(name = "proInfoDetail.brandId", required = true), @Valid(name = "proInfoDetail.proName", required = true),
			@Valid(name = "proInfoDetail.supplierId", required = true), @Valid(name = "proInfoDetail.proType", required = true),
			@Valid(name = "proInfoDetail.supplierName", required = true), @Valid(name = "proInfoDetail.supplierCatName", required = false),
			@Valid(name = "proInfoDetail.unint", required = true), @Valid(name = "proInfoDetail.specifications", required = true),
			@Valid(name = "proInfoDetail.weight", required = true, maxValue = 999999.9999), @Valid(name = "proInfoDetail.netWeight", required = true, maxValue = 999999.9999),
			@Valid(name = "proInfoDetail.isExchangeIntegral", required = true, regex = "1|0"), @Valid(name = "proInfoDetail.businessType", required = true),
			@Valid(name = "proInfoDetail.isVirtual", required = false, regex = "1|0"), @Valid(name = "proInfoDetail.catProps.proId", required = false),
			@Valid(name = "proInfoDetail.catProps.propId", required = false), @Valid(name = "proInfoDetail.catProps.propType", required = false),
			@Valid(name = "proInfoDetail.catProps.propValId", required = false), @Valid(name = "proInfoDetail.catProps.propVal", required = false),
			@Valid(name = "proInfoDetail.catProps.propertyVal", required = false), @Valid(name = "proInfoDetail.backProInfoPrices.proId", required = false),
			@Valid(name = "proInfoDetail.backProInfoPrices.priceType", required = true), @Valid(name = "proInfoDetail.backProInfoPrices.sysId", required = true),
			@Valid(name = "proInfoDetail.backProInfoPrices.price", required = false), })
	public Result insertProductInfo(@RequestBody @ApiParam BackProductInfoDetailVo proInfoDetail) throws CustomException {
		if (proInfoDetail.getId() == null) {
			// 新增
			Result result = productInfoService.insertProductInfo(proInfoDetail);
			return result;
		} else {
			if (proInfoDetail.getProType().equals(ProductType.PRO)) {
				// 修改 正价商品
				Result result = productInfoService.updateProductInfo(proInfoDetail);
				return result;
			} else if (proInfoDetail.getProType().equals(ProductType.EXPERIENCE)) {
				// 修改 体验品
				return productInfoService.updateExperiencePro(proInfoDetail);
			}
			return null;
		}
		
	}
	
	@ResponseBody
	@RequestMapping(value = "/creatExperiencePro", method = RequestMethod.POST)
	@ApiOperation(value = "后台创建体验商品SKU-huihang", notes = "后台创建体验商品SKU")
	@Valids({ @Valid(name = "proId", required = false), @Valid(name = "experiencePro.id", required = false), @Valid(name = "experiencePro.proSku", required = false),
			@Valid(name = "experiencePro.proName", required = true), @Valid(name = "experiencePro.supplierId", required = true),
			@Valid(name = "experiencePro.supplierName", required = true), @Valid(name = "experiencePro.isExchangeIntegral", required = true),
			@Valid(name = "experiencePro.brandId", required = true), @Valid(name = "experiencePro.unint", required = true),
			@Valid(name = "experiencePro.specifications", required = true), @Valid(name = "experiencePro.weight", required = true),
			@Valid(name = "experiencePro.businessType", required = true), @Valid(name = "experiencePro.backProInfoPrices.priceType", required = true),
			@Valid(name = "experiencePro.backProInfoPrices.price", required = false), @Valid(name = "experiencePro.backProInfoPrices.sysId", required = false), })
	@ApiImplicitParams({ @ApiImplicitParam(name = "proId", value = "通用商品ID", required = true, dataType = "long", paramType = "query") })
	public Result creatExperiencePro(@RequestParam(required = true) Long proId, @RequestBody @ApiParam BackProductInfoDetailVo experiencePro) throws CustomException {
		// 新增
		return productInfoService.creatExperiencePro(experiencePro, proId);
		
	}
	
	// @Jsons({ @Json(type = ProductDetailVo.class), @Json(type = PropValVo.class), @Json(type = PropertiesVal.class, include = "id,catPropId,propVal"), })
	@ResponseBody
	@RequestMapping(value = "/searchProductInfo", method = RequestMethod.GET)
	@ApiOperation(value = "收银V4-商品，分类，品牌查询列表-wuyicheng", notes = "收银V4-商品，分类，品牌查询列表-wuyicheng")
	@Valids({ @Valid(name = "sysId", required = true) })
	@ApiImplicitParams({ @ApiImplicitParam(name = "sysId", value = "系统ID", required = true, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "productSku", value = "商品编码", required = false, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "categoryId", value = "分类ID", required = false, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "brandId", value = "品牌ID", required = false, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "ignoreProSkus", value = "忽略商品Sku", required = false, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "isIgnoreNoPurchasePrice", value = "是否过滤没有进货价商品", required = false, dataType = "short", paramType = "query"),
			@ApiImplicitParam(name = "productPriceId", value = "代理商等级ID（商品价格对应ID）", required = true, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "sort", value = "排序字段salesPrice(零售价),purchasePrice(进货价)", required = false, dataType = "string", paramType = "query"), //
			@ApiImplicitParam(name = "order", value = "升序还是降序（DESC/ASC）", required = false, dataType = "long", paramType = "query"), //
			@ApiImplicitParam(name = "pageNumber", value = "页码", required = true, dataType = "integer", paramType = "query"),
			@ApiImplicitParam(name = "pageSize", value = "单页记录数", required = true, dataType = "integer", paramType = "query"), })
	
	public Result<SearchProductInfoVo> searchProductInfo(Long sysId, @RequestParam(required = false) String productSku, //
			@RequestParam(required = false) Long categoryId, @RequestParam(required = false) Long brandId, //
			@RequestParam(required = false) String ignoreProSkus, //
			@RequestParam(required = false) Short isIgnoreNoPurchasePrice, Long productPriceId, //
			@RequestParam(required = false) String sort, @RequestParam(required = false) String order, //
			Integer pageNumber, Integer pageSize) throws CustomException {
		Result<SearchProductInfoVo> result = new Result<SearchProductInfoVo>();
		result = productInfoService.searchProductInfo(sysId, productSku, ignoreProSkus, categoryId, brandId, productPriceId, isIgnoreNoPurchasePrice, pageNumber, pageSize, sort,
				order);
		return result;
	}
	
	@ResponseBody
	@RequestMapping(value = "/findProductByCashier", method = RequestMethod.GET)
	@ApiOperation(value = "收银V4-购物车商品查询-wuyicheng", notes = "收银V4-购物车商品查询-wuyicheng")
	@Valids({ @Valid(name = "sysId", required = true) })
	@ApiImplicitParams({ @ApiImplicitParam(name = "sysId", value = "系统ID", required = true, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "productSkus", value = "商品编码", required = true, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "categoryId", value = "分类ID", required = false, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "brandId", value = "品牌ID", required = false, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "status", value = "状态1启用2禁用", required = false, dataType = "short", paramType = "query"),
			@ApiImplicitParam(name = "isShelf", value = "上下架", required = false, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "isIgnoreNoPurchasePrice", value = "是否过滤没有进货价商品", required = false, dataType = "short", paramType = "query"),
			@ApiImplicitParam(name = "productPriceId", value = "代理商等级ID（商品价格对应ID:代理商等级31-单店铺代理，265-区域代理 ，266-专柜代理）", required = true, dataType = "string", paramType = "query"), //
			@ApiImplicitParam(name = "sort", value = "排序字段salesPrice(零售价),purchasePrice(进货价)", required = false, dataType = "string", paramType = "query"), //
			@ApiImplicitParam(name = "order", value = "升序还是降序（DESC/ASC）", required = false, dataType = "long", paramType = "query"), //
	
	})
	public Result<List<ProductCashierVo>> findProductByCashier(Long sysId, String productSkus, //
			@RequestParam(required = false) Long categoryId, @RequestParam(required = false) Long brandId, //
			@RequestParam(required = false) String isShelf, @RequestParam(required = false) Short status, //
			Long productPriceId, @RequestParam(required = false) Short isIgnoreNoPurchasePrice, //
			@RequestParam(required = false) String sort, @RequestParam(required = false) String order) throws CustomException {
		Result<List<ProductCashierVo>> result = new Result<List<ProductCashierVo>>();
		ProductSearchVo productSearchVo = new ProductSearchVo();
		productSearchVo.setBrandId(brandId);
		productSearchVo.setCatId(categoryId);
		productSearchVo.setProSkus(Arrays.asList(productSkus.split(",")));
		productSearchVo.setSysId(sysId);
		productSearchVo.setStatus(status);
		productSearchVo.setState(isShelf);
		productSearchVo.setProductPriceId(productPriceId);
		productSearchVo.setIsIgnoreNoPurchasePrice(isIgnoreNoPurchasePrice);
		productSearchVo.setIsFuzzyQuery(ProductSearchVo.IS_FUZZY_QUERY_NO_0);
		productSearchVo.setSort(sort);
		productSearchVo.setOrder(order);
		List<ProductCashierVo> productCashierVos = productInfoService.findProductByCashier(productSearchVo, null);
		result.setData(productCashierVos);
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
}
